package Controllers;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateNTime {

    public static boolean checkDelTimeHoaDon(Date thoiDiemLap, Date thoiDiemHienTai) { //Dinh dang HH:mm:ss dd-MM-yyyy - false là ko xóa - true có thể xóa
        try {
            long diff = thoiDiemHienTai.getTime() - thoiDiemLap.getTime();
            long diffSeconds = diff / 1000 % 60;
            long diffMinutes = diff / (60 * 1000) % 60;
            long diffHours = diff / (60 * 60 * 1000) % 24;
            long diffDays = diff / (24 * 60 * 60 * 1000);

            System.out.print(diffDays + " days, ");
            System.out.print(diffHours + " hours, ");
            System.out.print(diffMinutes + " minutes, ");
            System.out.print(diffSeconds + " seconds.");
            return (diffDays > 0 || diffHours > 0) ? false : (diffMinutes > 30) ? false : (diffMinutes != 30 || diffSeconds <= 0);
        } catch (Exception e) {
            return false;
        }
    }

    public static int compareDate(Date ngayA, Date ngayB) //-1 ngay A lon hon 1 ngay B lon hon 0 bang nhau
    {
        try {
            long diff = ngayB.getTime() - ngayA.getTime();
            return diff == 0 ? 0 : diff > 0 ? 1 : -1;
        } catch (Exception e) {
            return 0;
        }
    }

    public static boolean checkTuoi(Date ngaySinhChon)//Dinh dang dd-MM-yyyy - false là sai - true phù hợp
    {
        try {
            int tuoiChuan = 18;
            Calendar cal = Calendar.getInstance();
            Date ngayHienTai = cal.getTime();

            long diff = ngayHienTai.getTime() - ngaySinhChon.getTime();
//            long diffSeconds = diff / 1000 % 60;
//            long diffMinutes = diff / (60 * 1000) % 60;
//            long diffHours = diff / (60 * 60 * 1000) % 24;
//            long diffDays = diff / (24 * 60 * 60 * 1000);
            long diffYears = (diff / (1000 * 60 * 60 * 24)) / 365;
            //  System.out.println(diffYears);
            return (diffYears >= tuoiChuan);
        } catch (Exception e) {
            return false;
        }
    }
}
